<template>
  <FModal header="转办" ref="refFModal" :loading="loading" width="600" @ok="userChange">
    <SingleUserSelector v-model="user" v-model:realname="realname"/>
  </FModal>
</template>
<script setup>
import FModal from '@/components/FModal/index.vue';
import {shallowRef, unref} from 'vue';
import SingleUserSelector from '@/components/SingleUserSelector';
import {isEmpty} from '@/utils/CommonUtils';
import {ElMessage} from 'element-plus';

const refFModal = shallowRef();
const user = shallowRef();
const realname = shallowRef();
const emits = defineEmits(['userChange']);
const loading = shallowRef(false);

function setData() {
  refFModal.value.open();
  user.value = undefined;
}

function userChange() {
  let data = unref(user);
  if (isEmpty(data)) {
    ElMessage({
      message: '请选人',
      type: 'warning',
    });
    return;
  }
  loading.value = true;
  emits('userChange', unref(user), unref(realname));
}

defineExpose({
  setData
});
</script>
